<?php
namespace app\user\controller;

use app\common\controller\UserBase;
use think\facade\Request;
use think\facade\Db;
use think\facade\Session;

use app\user\model\CustomerConfig as CC;
use app\common\model\User;

class CustomerConfig extends UserBase
{
    //客户列表
    public function index()
    {
        $customer = new CC();
        $list = $customer->order('sort_order desc,update_time desc,id desc')->paginate(6);
        return $this->fetch('index',[
            'list' => $list,
        ]);
    }
    //新增
    public function add()
    {
        if ($this->request->isPost()) {
            $param = $this->request->param();
            $param['shop_id'] = ShopId();
            //验证规则
            $verify = input('_verify', true);
            if($verify!='0'){
                try{
                    $this->validate($param, 'customer_config');
                }catch (\Exception $e){
                    $this->error($e->getMessage());
                }
            }
            CC::create($param);
            insert_user_log('新增参数:'.$param['name']);
            $this->success('操作成功');
        }
        return $this->fetch('save',['field_list' => CC::field_list()]);
    }
    //编辑
    public function edit($id)
    {
        if ($this->request->isPost()) {
            $param = $this->request->param();
            //验证规则
            $verify = input('_verify', true);
            if($verify!='0'){
                try{
                    $this->validate($param, 'customer_config');
                }catch (\Exception $e){
                    $this->error($e->getMessage());
                }
            }
            CC::update($param,['id'=>$param['id']]);
            insert_user_log('修改参数');
            $this->success('操作成功');
        }
        $data = CC::where('id',$id)->find();
        return $this->fetch('save',['data'=>$data,'field_list' => CC::field_list()]);
    }
    //删除
    public function del()
    {
        if ($this->request->isPost()) {
            $param = $this->request->param();
            CC::destroy($param['id']);
            insert_user_log('删除参数');
            $this->success('删除成功');
        }
    }
    
    
}
